<template>
  <div class="divBox">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <div class="container">
          <el-form inline size="small" label-width="110px">
            <!--<el-form-item label="审核状态">
              <el-select
                v-model="tableFrom.status" @change.capture="getList(1)"
                placeholder="请选择"
                class="filter-item selWidth"
                clearable
                @change="getList(1)"
              >
                <el-option
                  v-for="item in statusList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>-->

          </el-form>
        </div>
      <!--  <el-tabs v-if="headeNum.length > 0" v-model="tableFrom.is_type" @tab-click="getList(1)">
          <el-tab-pane v-for="(item,index) in headeNum" :key="index" :name="item.type.toString()" :label="item.title"/>
        </el-tabs>-->
      </div>
      <el-table
        v-loading="listLoading"
        :data="tableData.data"
        style="width: 100%"
        size="small"
      >
        <el-table-column
          label="UID"
          prop="uid"
          min-width="100" />
        <el-table-column
          label="申请人"
          prop="nickname"
          min-width="100" />
        <el-table-column label="头像" min-width="110">
          <template slot-scope="scope">
            <div class="demo-image__preview">
              <el-image v-if="scope.row.avatar && scope.row.avatar!=1"
                :src="scope.row.avatar"
                class="mr5"
                :preview-src-list="[scope.row.avatar]"
              />
              <el-image v-else
                        src="https://gdw.mage168.com/static/f.png"
                        class="mr5"

              />
            </div>
            </template>
        </el-table-column>
        <el-table-column
          label="分红比例"
          prop="bonus_ratio"
          min-width="100" >
          <template  slot-scope="scope">
            <div style="cursor:pointer" @click="open(scope.row.business_apply_id,scope.row.bonus_ratio)">
              {{scope.row.bonus_ratio}}
              <i class="el-icon-edit"></i>
            </div>
          </template>
        </el-table-column>
        <el-table-column
          label="所属站点"
          prop="zhandian_name"
          min-width="100" />
        <el-table-column
          label="姓名"
          prop="name"
          min-width="100" />
        <el-table-column
          label="手机号"
          prop="phone"
          min-width="100" />
        <el-table-column
          label="身份证"
          prop="sfz"
          min-width="100" />


        <el-table-column label="申请资料" min-width="210">
          <template slot-scope="scope">
            <div class="demo-image__preview">
              <el-image v-if="i!=1"
                v-for="(i,index) in scope.row.imgArr"
                :key="index"
                :src="i"
                class="mr5"
                :preview-src-list="[i]"
              />

            </div>
          </template>
        </el-table-column>

        <el-table-column
          prop="create_time"
          label="发布时间"
          min-width="100"
        />

        <el-table-column
          label="状态"
          min-width="100"
        >
          <template slot-scope="scope">
            <span>{{ scope.row.status | communityStatus }}</span>
            <span
              v-if="scope.row.status == -1"
              style="display: block; font-size: 12px; color: red;"
            >原因 {{ scope.row.fail_msg }}</span>
          </template>
        </el-table-column>

        <el-table-column label="操作" min-width="100" fixed="right">
          <template slot-scope="scope">
             <el-button type="text" size="small" @click="onDetail(scope.row)">详情</el-button>


            <el-button v-if="scope.row.status == 0 || scope.row.status == -2" type="text" size="small"
                       @click="onAudit(scope.row)">审核</el-button>

          </template>
        </el-table-column>
      </el-table>
      <div class="block">
        <el-pagination
          :page-sizes="[20, 40, 60, 80]"
          :page-size="tableFrom.limit"
          :current-page="tableFrom.page"
          layout="total, sizes, prev, pager, next, jumper"
          :total="tableData.total"
          @size-change="handleSizeChange"
          @current-change="pageChange"
        />
      </div>
    </el-card>
    <!--审核-->
    <el-dialog v-if="dialogVisible" :title="isExamine ? '审核' : '详情'" :visible.sync="dialogVisible" width="700px">
      <div v-loading="loading">
        <el-form :model="formData" label-width="100px" ref="formData" :rules="rules">

        <el-form-item >
          <div  style="display: inline-block; margin: 0 10px 10px 0">
            <el-image v-for="(i,index) in formData.imgArr" :key="index" style="width: 100px; height: 100px"
              :src="i" v-if="i!=1"
              class="mr5"
              :preview-src-list="[i]"
            />

          </div>
        </el-form-item>

        <el-form-item label="省市区：" v-if="formData.province">
          <div>{{formData.province}}{{formData.city}}{{formData.district}}</div>
        </el-form-item>
        <el-form-item label="详情：" v-if="formData.detail">
            <span>{{formData.detail}}</span>
          </el-form-item>
        <el-form-item label="用户：" >
          <span>{{formData.nickname}}</span>
        </el-form-item>
          <el-form-item label="姓名：" >
            <span>{{formData.name}}</span>
          </el-form-item>

          <el-form-item label="手机号：" >
            <span>{{formData.phone}}</span>
          </el-form-item>
        <el-form-item label="申请时间：">
          <span>{{formData.create_time}}</span>
        </el-form-item>

        <el-form-item v-if="!isExamine && formData.status==1" label="审核通过时间：">
          <span>{{formData.check_time}}</span>
        </el-form-item>
        <el-form-item v-if="isExamine" label="审核状态：" prop="status">
          <el-radio-group v-model="ruleForm.status">
            <el-radio :label="1">通过</el-radio>
            <el-radio :label="-1">拒绝</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item v-if="ruleForm.status===-1 && isExamine" label="原因" prop="msg">
          <el-input v-model="ruleForm.msg" type="textarea" placeholder="请输入原因" />
        </el-form-item>
        <el-form-item v-if="isExamine">
          <el-button type="primary" @click="onSubmit">提交</el-button>
        </el-form-item>
      </el-form>
      </div>
    </el-dialog>
  </div>
</template>

<script>

import {
   communityStatusApi, communityUpdateApi, examinelDetailApi, communityDeleteApi, communityOffApi,
   communityCateOptionApi, communityTopicOptionApi, examineListApi,examinelshApi,updateYWYRatio
} from '@/api/community'
import Template from "@/views/app/wechat/wxTemplate/index.vue";
import {updateShareRatio} from "@/api/user";
export default {
  name: 'communityTopic',
  components: {Template},
  data() {
    return {
      moren: require("@/assets/images/f.png"),
      colors: ['#99A9BF', '#F7BA2A', '#FF9900'],
      isChecked: false,
      listLoading: true,
      tableData: {
        data: [],
        total: 0
      },
      tableFrom: {
        page: 1,
        is_type:2,
        limit: 20,
        status: "",
        keyword: ""
      },
      statusList: [
        { label: "审核通过", value: 1 },
        { label: "待审核", value: 0 },
        { label: "审核未通过", value: -1 },
        { label: "下架", value: -2 },
      ],
      headeNum: [
        {title: "个人认证", count: 0, type: 0}
      ],
      cateSelect: [],
      topicSelect: [],
      dialogVisible: false,
      loading: false,
      isExamine: false,
      community_id: "",
      formData: {},
      rules: {
        status: [
          { required: true, message: '请选择审核状态', trigger: 'change' }
        ],
        msg: [
          { required: true, message: '请填写拒绝原因', trigger: 'blur' }
        ]
      },
      ruleForm: {
        msg: '',
        status: 1,
      },
    }
  },
  mounted() {
    this.getList(1)

  },
  methods: {
    open(id,share_ratio){
      let that = this
      this.$prompt('当前比例：' + share_ratio + '%', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消'
      }).then(({ value }) => {
        updateYWYRatio({id:id,bonus_ratio:value}).then(result => {
          that.$message.success(result.message)
          that.getList(1)
        })
      }).catch(() => {

      });
    },
    // 分类列表；
    getCateSelect() {
      communityCateOptionApi()
        .then((res) => {
          this.cateSelect = res.data;
        })
        .catch((res) => {
          this.$message.error(res.message);
        });
    },

    // 话题列表；
    getTopicSelect() {
      communityTopicOptionApi()
        .then((res) => {
          this.topicSelect = res.data;
        })
        .catch((res) => {
          this.$message.error(res.message);
        });
    },
    // 列表
    getList(num) {
      this.listLoading = true
      this.tableFrom.page = num ? num : this.tableFrom.page
      this.tableFrom.type = this.tableFrom.is_type
      examineListApi(this.tableFrom).then(res => {
        let list = res.data.list

        list.forEach(e => {
            if(e.pics1) {
               e.imgArr = [...e.pics1, ...e.pics2]
            }
        });
        console.log(list,'aaaaaaaaaaaa')
        this.tableData.data = list

        this.tableData.total = res.data.count
        this.listLoading = false
      }).catch(res => {
        this.listLoading = false
        this.$message.error(res.message)
      })
    },
    pageChange(page) {
      this.tableFrom.page = page
      this.getList('')
    },
    handleSizeChange(val) {
      this.tableFrom.limit = val
      this.getList('')
    },
    // 编辑
    onEdit(id) {
      this.$modalForm(communityUpdateApi(id)).then(() => this.getList(''))
    },
    // 查看评论
    onReply(id) {
      this.$router.push({
        path: "reply",
        query: {
          community_id: id,
        },
      });
    },
    // 审核
    onAudit(item) {
      if(this.tableFrom.type == 0){
            this.community_id = item.purchasers_apply_id;
      }
      if(this.tableFrom.type == 1){
          this.community_id = item.delivery_apply_id;
      }
      if(this.tableFrom.type == 2){
          this.community_id = item.business_apply_id;
      }

      this.dialogVisible = true;
      this.isExamine = true;
      examinelDetailApi(this.community_id,{type:this.tableFrom.type}).then((res) => {
        let formData = res.data
        if(this.tableFrom.is_type==0){
          formData.imgArr = [...formData.business_image,...formData.store_images,formData.bank_back_image,formData.bank_just_image,formData.id_national_image,formData.id_portrait_image]
        }
        if(this.tableFrom.is_type==1){
          formData.imgArr = [formData.drive_back_image,formData.drive_just_image,formData.id_national_image,formData.id_portrait_image]
        }

        this.formData = formData
      }).catch(({ message }) => {
        this.$message.error(message)
      })
    },
    // 详情
    onDetail(item) {
      if(this.tableFrom.type == 0){
        this.community_id = item.purchasers_apply_id;
      }
      if(this.tableFrom.type == 1){
        this.community_id = item.delivery_apply_id;
      }
      if(this.tableFrom.type == 2){
        this.community_id = item.business_apply_id;
      }
      this.dialogVisible = true;
      this.isExamine = false;
      examinelDetailApi(this.community_id,{type:this.tableFrom.type}).then((res) => {
        let formData = res.data
        if(this.tableFrom.is_type==0){
          formData.imgArr = [...formData.business_image,...formData.store_images,formData.bank_back_image,formData.bank_just_image,formData.id_national_image,formData.id_portrait_image]
        }
        if(this.tableFrom.is_type==1){
          formData.imgArr = [formData.drive_back_image,formData.drive_just_image,formData.id_national_image,formData.id_portrait_image]
        }
        this.formData = formData
      }).catch(({ message }) => {
        this.$message.error(message)
      })
    },
    // 强制下架
    onOff(id){
      this.$modalForm(communityOffApi(id)).then(() => this.getList(''))
    },
    onSubmit() {
      this.ruleForm.type = this.tableFrom.type
      examinelshApi(this.community_id,this.ruleForm).then(res => {
        this.$message.success(res.message)
        this.dialogVisible = false
        this.getList('')
      }).catch(res => {
        this.$message.error(res.message)
      })
    },
    // 删除
    handleDelete(id, idx) {
      this.$modalSure('确定删除该文章').then(() => {
        communityDeleteApi(id).then(({ message }) => {
          this.$message.success(message)
          this.getList('')
        }).catch(({ message }) => {
          this.$message.error(message)
        })
      })
    },
    onchangeIsShow(row) {
      communityStatusApi(row.community_id, row.is_show).then(({ message }) => {
        this.$message.success(message)
      }).catch(({ message }) => {
        this.$message.error(message)
      })
    }
  }
}
</script>

<style scoped lang="scss">
.box-container {
  overflow: hidden;
}
.box-container .list {
  float: left;
  line-height: 40px;
}
.box-container .sp {
  width: 50%;
}
.box-container .sp3 {
  width: 33.3333%;
}
.box-container .sp100 {
  width: 100%;
}
.box-container .list .name {
  display: inline-block;
  width: 150px;
  text-align: right;
  color: #606266;
}
.box-container .list.image {
  margin-bottom: 40px;
}
.box-container .list.image img {
  position: relative;
  top: 40px;
}
/deep/.el-form-item__content .el-rate{
  position: relative;
  top: 8px;
}
</style>
